﻿using System;
using System.Linq;
using System.Collections.Generic;

namespace Ayatta.Contract.Domain
{
    public class UserRecharge : BaseEntity<string>
    {
        /// <summary>
        /// 
        /// </summary>
        public int UserId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public decimal Amount { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public decimal Paid { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public decimal Refunded { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int Category { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int PackageId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Gateway { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Extra { get; set; }

        /// <summary>
        /// 状态 0为成功 1为未支付 2为失败*/
        /// </summary>
        public byte Status { get; set; }


        public string StatusText { get { return StatusDic.FirstOrDefault(o => o.Key == Status).Value; } }

        public static IDictionary<byte,string>  StatusDic
        {
            get
            {
                var dic = new Dictionary<byte, string>();
                dic.Add(0, "成功");
                dic.Add(1, "未支付");
                dic.Add(2, "失败");
                return dic;
            }
        }

        public PayTrade ToPayTrade(PaymentEBank eBank,string ipAddress)
        {
            var now = DateTime.Now;
            var trade = new PayTrade();
            var id = now.ToString("yyMMddHHmmssffff");

            if (eBank != null)
            {
                trade.Id = id;
                trade.UserId = UserId;
                trade.Category = 0;
                trade.AssociatedId = Id;
                trade.Amount = Amount;
                trade.Balance = 0;
                trade.UseBalance = false;
                trade.PaymentCategory = 1;
                trade.Gateway = eBank.GatewayCode;
                trade.BankName = eBank.PaymentBank.Name;
                trade.PaymentEBankId = eBank.Id;
                trade.PaymentPlatformId = eBank.PlatformId;
                trade.CardNo = string.Empty;
                trade.CardPwd = string.Empty;
                trade.CardAmount = string.Empty;
                trade.IpAddress = ipAddress;
                trade.ThirdPartyNo = string.Empty;
                trade.Extra = string.Empty;
                trade.Status = 1;
                trade.CreatedBy = CreatedBy;
                trade.CreatedOn = CreatedOn;
            }
            return trade;
        }
    }

    public enum UserRecharegStatus : byte
    {

    }
}